<!--
 * @FilePath     : /study_code/layui/21-6.html
 * @Description  : element.render() 动态渲染导航
 * @Date         : 2025-04-15 14:02:59
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-15 14:18:05
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
  </head>
  <body>
    <div id="test" lay-filter="demo-filter-nav"></div>

    <script src="/layui/dist/layui.js"></script>
    <script>
      layui.use(function () {
        var element = layui.element
        var $ = layui.$
        // 动态插入导航元素
        $('#test').html(`
          <div class="layui-nav" lay-filter="demo-filter-nav">
            <li class="layui-nav-item layui-this"><a href="">选中</a></li>
            <li class="layui-nav-item"><a href="">菜单</a></li>
            <!-- … -->
          </div>
        `)

        /**
         * @brief: 渲染导航组件
         * @param {String} 'nav' 渲染导航的固定值
         * @param {String} filter 对应导航容器 lay-filter 的属性值或 2.9.15+ 指定元素的 jq 对象。
         * @return {*}
         */
        element.render('nav', 'demo-filter-nav')
      })
    </script>
  </body>
</html>
